// 消息弹窗
export const showToast = (title, icon = 'none') => {
  uni.showToast({
    title,
    icon,
    duration: 2000
  })
}

// localstorage
export function getStorage(key) {
  return uni.getStorageSync(key)
}

export function setStorage(key, value) {
  return uni.setStorageSync(key, value)
}

export function removeStorage(key) {
  return uni.removeStorageSync(key)
}

export function tansParams(params) {
  let result = ''
  for (const propName of Object.keys(params)) {
    const value = params[propName]
    var part = encodeURIComponent(propName) + "="
    if (value !== null && value !== "" && typeof (value) !== "undefined") {
      if (typeof value === 'object') {
        for (const key of Object.keys(value)) {
          if (value[key] !== null && value[key] !== "" && typeof (value[key]) !== 'undefined') {
            let params = propName + '[' + key + ']'
            var subPart = encodeURIComponent(params) + "="
            result += subPart + encodeURIComponent(value[key]) + "&"
          }
        }
      } else {
        result += part + encodeURIComponent(value) + "&"
      }
    }
  }
  return result
}

// 通用dicts方法
export const getDicts = (data, value, type) => {
  return data.find((item) => item.value == value)[type];
};
